package Day48.day26;


import java.util.Scanner;

public class t1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        int result = findShortestPalindrome(input);
        System.out.println(result);
        scanner.close();
    }

    public static int findShortestPalindrome(String s) {
        int minLen = Integer.MAX_VALUE;
        boolean found = false;

        // 遍历所有可能的子串
        for (int i = 0; i < s.length(); i++) {
            for (int j = i + 1; j < s.length(); j++) {
                String sub = s.substring(i, j + 1);
                if (isPalindrome(sub)) {
                    int len = sub.length();
                    if (len > 1 && len < minLen) {
                        minLen = len;
                        found = true;
                    }
                }
            }
        }

        // 如果找到了符合条件的回文子串，返回最短长度
        if (found) {
            return minLen;
        } else {
            return -1; // 不存在长度超过1的回文子串
        }
    }

    public static boolean isPalindrome(String s) {
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}


